package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.MesProductDamage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:33:33
 */
@Repository
public class MesProductDamageDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(MesProductDamageDao.class);

    public MesProductDamage insert(final MesProductDamage mesProductDamage) {
        insert("MesProductDamage.insert", mesProductDamage);
        return mesProductDamage;
    }

    public Boolean updateInfoById(final MesProductDamage mesProductDamage) {
        return update("MesProductDamage.updateInfoById", mesProductDamage) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("MesProductDamage.updateInfoByQuery", query) > 0;
    }

    public MesProductDamage selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("MesProductDamage.selectById", query);
    }

    public List<MesProductDamage> selectByQuery(final Query query) {
        return queryForList("MesProductDamage.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("MesProductDamage.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        MesProductDamage mesProductDamage = new MesProductDamage();
        mesProductDamage.setDeleteFlag(1);
        mesProductDamage.setId(id);
        mesProductDamage.setEntId(entId);

        return update("MesProductDamage.updateInfoById", mesProductDamage) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("MesProductDamage.deleteById", query) > 0;
    }
}